//
//  MineHeaderView.m
//  Tongcheng
//
//  Created by 邢广范 on 2017/4/3.
//  Copyright © 2017年 Tongcheng. All rights reserved.
//h181

#import "MineHeaderView.h"
#import "UIImageView+AFNetworking.h"

@interface MineHeaderView ()


@property (weak, nonatomic) IBOutlet UIButton *fuzhiBtn;
@property (weak, nonatomic) IBOutlet UIView *buyVipView;
@property (weak, nonatomic) IBOutlet UIView *yanzhengView;
- (IBAction)fuzhiBtnClick:(id)sender;
@property (weak, nonatomic) IBOutlet UILabel *vipLabel;
@property (weak, nonatomic) IBOutlet UILabel *yanzhengLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *idLabel;
@property (weak, nonatomic) IBOutlet UILabel *iCode;

@end

@implementation MineHeaderView

- (void)setModel:(MineUserinfoDataModel *)model
{
    [self.avatarImageView setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:nil];
    
    if ([model.user_rank isEqualToString:@"1"]) {
        self.vipLabel.text = @"VIP";
    }else{
        self.vipLabel.text = @"立即开通";
    }
    
    if ([model.ismobile isEqualToString:@"1"]) {
        self.yanzhengLabel.text = @"已验证";
    }else{
        self.yanzhengLabel.text = @"立即认证";
    }
    self.nameLabel.text = model.user_nicename;
    self.idLabel.text = [NSString stringWithFormat:@"ID:%@", model._id];
    self.iCode.text = [NSString stringWithFormat:@"邀请码:%@",model.icode];
}

+ (instancetype)gainMineHeaderView
{
    return [[NSBundle mainBundle] loadNibNamed:@"MineHeaderView" owner:self options:nil].lastObject;
}

- (void)awakeFromNib
{
    [super awakeFromNib];
    self.avatarImageView.layer.cornerRadius = 32.5;
    self.avatarImageView.layer.masksToBounds = YES;
    
    UITapGestureRecognizer *avatarTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(avatarClick)];
    self.avatarImageView.userInteractionEnabled = YES;
    [self.avatarImageView addGestureRecognizer:avatarTap];
    
    UITapGestureRecognizer *vipTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buyVipClick)];
    [self.buyVipView addGestureRecognizer:vipTap];
    
    UITapGestureRecognizer *yanzhengTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(yanzhengClick)];
    [self.yanzhengView addGestureRecognizer:yanzhengTap];
}

- (void)avatarClick
{
    if ([self.delegate respondsToSelector:@selector(clickAvatarImageViewWith:)]) {
        [self.delegate clickAvatarImageViewWith:self.avatarImageView];
    }
}

- (void)buyVipClick
{
    if ([self.delegate respondsToSelector:@selector(clickBuyVipBtn)]) {
        [self.delegate clickBuyVipBtn];
    }
}

- (void)yanzhengClick
{
    if ([self.delegate respondsToSelector:@selector(clickYanzhengBtn)]) {
        [self.delegate clickYanzhengBtn];
    }
}

- (IBAction)fuzhiBtnClick:(id)sender {
}
@end
